﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.ShaderVariantCollection
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Rendering;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>ShaderVariantCollection records which shader variants are actually used in each shader.</para>
  /// </summary>
  public sealed class ShaderVariantCollection : Object
  {
    /// <summary>
    ///   <para>Number of shaders in this collection (Read Only).</para>
    /// </summary>
    public extern int shaderCount { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Number of total varians in this collection (Read Only).</para>
    /// </summary>
    public extern int variantCount { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Is this ShaderVariantCollection already warmed up? (Read Only)</para>
    /// </summary>
    public extern bool isWarmedUp { [NativeName("IsWarmedUp"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern bool AddVariant(Shader shader, PassType passType, [Unmarshalled] string[] keywords);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern bool RemoveVariant(Shader shader, PassType passType, [Unmarshalled] string[] keywords);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern bool ContainsVariant(Shader shader, PassType passType, [Unmarshalled] string[] keywords);

    /// <summary>
    ///   <para>Remove all shader variants from the collection.</para>
    /// </summary>
    [NativeName("ClearVariants")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void Clear();

    /// <summary>
    ///   <para>Prewarms all shader variants in this shader variant collection.</para>
    /// </summary>
    [NativeName("WarmupShaders")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void WarmUp();

    [NativeName("CreateFromScript")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Internal_Create([Writable] ShaderVariantCollection svc);

    /// <summary>
    ///   <para>Create a new empty shader variant collection.</para>
    /// </summary>
    public ShaderVariantCollection() => ShaderVariantCollection.Internal_Create(this);

    public bool Add(ShaderVariantCollection.ShaderVariant variant)
    {
      return this.AddVariant(variant.shader, variant.passType, variant.keywords);
    }

    public bool Remove(ShaderVariantCollection.ShaderVariant variant)
    {
      return this.RemoveVariant(variant.shader, variant.passType, variant.keywords);
    }

    public bool Contains(ShaderVariantCollection.ShaderVariant variant)
    {
      return this.ContainsVariant(variant.shader, variant.passType, variant.keywords);
    }

    /// <summary>
    ///   <para>Identifies a specific variant of a shader.</para>
    /// </summary>
    public struct ShaderVariant
    {
      /// <summary>
      ///   <para>Shader to use in this variant.</para>
      /// </summary>
      public Shader shader;
      /// <summary>
      ///   <para>Pass type to use in this variant.</para>
      /// </summary>
      public PassType passType;
      /// <summary>
      ///   <para>Array of shader keywords to use in this variant.</para>
      /// </summary>
      public string[] keywords;

      [FreeFunction]
      [NativeConditional("UNITY_EDITOR")]
      [MethodImpl(MethodImplOptions.InternalCall)]
      private static extern string CheckShaderVariant(
        Shader shader,
        PassType passType,
        string[] keywords);

      /// <summary>
      ///   <para>Creates a ShaderVariant structure.</para>
      /// </summary>
      /// <param name="shader"></param>
      /// <param name="passType"></param>
      /// <param name="keywords"></param>
      public ShaderVariant(Shader shader, PassType passType, params string[] keywords)
      {
        this.shader = shader;
        this.passType = passType;
        this.keywords = keywords;
        string message = ShaderVariantCollection.ShaderVariant.CheckShaderVariant(shader, passType, keywords);
        if (!string.IsNullOrEmpty(message))
          throw new ArgumentException(message);
      }
    }
  }
}
